﻿using SmartHotel.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartHotel.DAL
{
    public class HotelInfoDAL
    {
        public HotelInfoDAL(HotelContext hotelContext)
        {
            HotelContext = hotelContext;
        }

        public HotelContext HotelContext { get; }


        //添加
        //1.往上下文的数据集里添加数据(你要添加的对象)
        //2.savechanges
        public int Add(HotelInfo hotelInfo)
        {
            HotelContext.HotelInfos.Add(hotelInfo);
            return HotelContext.SaveChanges();
        }

        //查询 根据id查询酒店信息
        public HotelInfo GetHotelInfoById(int id) { 
            return HotelContext.HotelInfos.Where(x=>x.Id==id).FirstOrDefault();
        }

        //更新

        public int Update(HotelInfo hotelInfo) {
            var hotelinfo1 = GetHotelInfoById(hotelInfo.Id);
            if (hotelinfo1 != null) { 
                hotelinfo1.Address= hotelInfo.Address;
                hotelinfo1.PointX= hotelInfo.PointX;
                hotelinfo1.PointY= hotelInfo.PointY;
                hotelinfo1.Describe = hotelInfo.Describe;
                hotelinfo1.Phone = hotelInfo.Phone; 
                hotelinfo1.Name = hotelInfo.Name;
                hotelinfo1.ImgUrl = hotelInfo.ImgUrl;
            }
            return HotelContext.SaveChanges();
        }


        //分页


        //删除
    }
}
